# Maintainer: AlexWMF <alexxwmf@gmail.com>

_realname=qca
pkgbase=mingw-w64-${_realname}-qt5-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-qt5-git"
pkgver=2262.5f18ebc
pkgrel=1
pkgdesc="Qt Cryptographic Architecture (mingw-w64)"
arch=('any')
url="http://delta.affinix.com/qca/"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "git")
depends=("${MINGW_PACKAGE_PREFIX}-ca-certificates"
         "${MINGW_PACKAGE_PREFIX}-cyrus-sasl"
         "${MINGW_PACKAGE_PREFIX}-doxygen"
         "${MINGW_PACKAGE_PREFIX}-gnupg"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt"
         "${MINGW_PACKAGE_PREFIX}-nss"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-qt5")
install=${_realname}-qt5-git-${CARCH}.install
source=("${_realname}"::"git+https://anongit.kde.org/qca.git"
        "cyrus_sasl_linking.patch"
        "find_nss_cmake.patch"
        "qt5-custom-dirs.patch"
        "qca-mingw-pkg-config.patch"
        "qca-mingw-custom-certificates.patch")
sha256sums=('SKIP'
            'a5eeb6e2c3e884b54dc3837509d1cbde4611623a2888775ddb7e3868b1623e7c'
            '42a6f06f75213836d90b9b720afa29c1a9404ec0aedd332662abc694d3965fbd'
            '1734f88bb79bac16427b89d351c2775992743a791c28d4c04770c7055819880e'
            '3d682bcee66b48d50c9a037a4c0b088fb39059852f3a38950e64d55f2221539f'
            '2d601d3d7992c92f2cca450cf3906ab598a413733afa0eb5c15b85cf22aa27be')

pkgver() {
  cd ${srcdir}/${_realname}
  printf "%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -p1 -i ${srcdir}/cyrus_sasl_linking.patch
  patch -p1 -i ${srcdir}/find_nss_cmake.patch
  patch -p1 -i ${srcdir}/qt5-custom-dirs.patch
  patch -p1 -i ${srcdir}/qca-mingw-pkg-config.patch
  patch -p1 -i ${srcdir}/qca-mingw-custom-certificates.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  #QC_CERTSTORE_PATH=${MINGW_PREFIX}/ssl/certs/ca-bundle.crt
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;DQC_CERTSTORE_PATH=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_TESTS=False \
    -DQT4_BUILD=OFF \
    -DQCA_SUFFIX=qt5 \
    -DQCA_SYSTEMSTORE_PATH=../ssl/certs/ca-bundle.crt \
    -DQCA_INSTALL_IN_QT_PREFIX=ON \
    ../${_realname}

  make ${MAKEFLAGS}
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
